from typing import List


class Solution:
    def maximumElementAfterDecrementingAndRearranging(self, arr: List[int]) -> int:
        arr.sort()
        now = 0

        for num in arr:
            if num >= now + 1:
                now += 1

        return now


if __name__ == "__main__":
    print(Solution().maximumElementAfterDecrementingAndRearranging([2, 2, 1, 2, 1]))  # 2
    print(Solution().maximumElementAfterDecrementingAndRearranging([100, 1, 1000]))  # 3
    print(Solution().maximumElementAfterDecrementingAndRearranging([1, 2, 3, 4, 5]))  # 5
